package com.tedsoft.first_group_project;

import com.tedsoft.framework.*;

public class GameEngine {
	
	Player player;
	GameField gameField;
	Accel_meter accel_meter;
	GameDifficult gameDiff;
	
	public boolean gameOver = false;
	int currentGameFieldSize;
	
	public GameEngine(Game game)
	{
		player = new Player(game);
		gameField = new GameField();
		accel_meter = new Accel_meter();
		gameDiff = new GameDifficult();
		
		gameReset(game);
	}
	
	public void gameReset(Game game)
	{
		currentGameFieldSize = 10000;
		
		gameDiff.setCurDiff(e_difficulty.medium);
		
		gameDiff.setPlayerDifficulty(player);
		player.resetPlayer(game);
		
		gameField.generate_field(currentGameFieldSize, 0, game);
	}
	
	void update(float deltaTime, Game game)
	{
		player.update(deltaTime, game, gameField, accel_meter.state);
		
		gameField.update(deltaTime, (int)player.posX);
		
		//koniec gry jak sie skoncza zycia
		if(player.lives == 0)
		{
			gameOver = true;
		}
			
		//tutaj jak do konca planszy sie doleci
		if(player.posX >= (currentGameFieldSize + 50)) //dodajemy maly marginesik zeby na koncu jeszcze kawalek poleciec
		{
			gameOver = true;
		}	

	}
	
	void present(float deltaTime, Game game)
	{
		//Graphics g = game.getGraphics();

		gameField.present(deltaTime, game);
		player.present(deltaTime, game, gameField);
	}	 
}
